package com.card.hwatt.core;

import java.lang.reflect.Field;

/**
 * 对象工具类
 * @author Administrator
 *
 */
public final class ObjectUtil {
	
	/**
	 * 字段复制
	 * @param src
	 * @param target
	 */
	public static void fieldCopy(Object src, Object target) {
		Class<?> srcClass = src.getClass();
		Class<?> targetClass = target.getClass();
		for (Field field : targetClass.getFields()) {
			for (Field srcField : srcClass.getFields()) {
				if (!srcField.getName().equals(field.getName())
						|| srcField.getType() != field.getType()) {
					continue;
				}

				try {
					Object value = srcField.get(src);
					field.set(target, value);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		}
	}
}
